#!/usr/bin/env python
# encoding: utf-8
'''
@author: 王震
@license: 四川凡狼科技有限公司
@contact: 2668985108@qq.com
@file: user.py
@time: 2021/10/17 4:08 下午
@desc:
'''

from flask import Blueprint, request
from app.business.user.user import user_register as add, login, get_list, user_info as info
from app.public.sqlMethods import auto
from app.msg.resp import response_json
from app.msg.tips import *
from app.public.sqlMethods import set_content_type

user = Blueprint('user', __name__, url_prefix='/api')

'''
用户登录
'''


@user.route('/user/register', methods=['POST'])
@auto.login_required
def user_register():
    data = request.json
    if set_content_type():
        return response_json(code=tips['content_Type'], msg=tipsText['content_Type'])
    return add(data=data)


'''
用户登录
'''


@user.route('/user/login', methods=['POST'])
def user_login():
    data = request.json
    if set_content_type():
        return response_json(code=tips['content_Type'], msg=tipsText['content_Type'])
    return login(data=data)


'''
获取用户列表
'''


@user.route('/get/user/list', methods=['GET'])
@auto.login_required
def get_user_list():
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pagesSize', 10)
    return get_list(page_number=page_number, page_size=page_size)


'''
获取登录用户信息
'''


@user.route('/user/info', methods=['GET'])
@auto.login_required
def user_info():
    return info()
